home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / imap-3.0 / ANSI / c-client / dummydos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-30  |  11.4 KB  |  496 lines

  1. /*
  2.  * Program:    Dummy routines for DOS
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: MRC@CAC.Washington.EDU
  11.  *
  12.  * Date:    24 May 1993
  13.  * Last Edited:    30 June 1993
  14.  *
  15.  * Copyright 1993 by the University of Washington
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notice appears in all copies and that both the
  20.  * above copyright notice and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  32.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35.  
  36.  
  37. #include <ctype.h>
  38. #include <stdio.h>
  39. #include <errno.h>
  40. #include <fcntl.h>
  41. #include "mail.h"
  42. #include "osdep.h"
  43. #include "dummy.h"
  44. #include "misc.h"
  45.  
  46. /* Dummy routines */
  47.  
  48.  
  49. /* Driver dispatch used by MAIL */
  50.  
  51. DRIVER dummydriver = {
  52.   "dummy",            /* driver name */
  53.   (DRIVER *) NIL,        /* next driver */
  54.   dummy_valid,            /* mailbox is valid for us */
  55.   dummy_parameters,        /* manipulate parameters */
  56.   dummy_find,            /* find mailboxes */
  57.   dummy_find_bboards,        /* find bboards */
  58.   dummy_find_all,        /* find all mailboxes */
  59.   dummy_find_all_bboards,    /* find all bboards */
  60.   dummy_subscribe,        /* subscribe to mailbox */
  61.   dummy_unsubscribe,        /* unsubscribe from mailbox */
  62.   dummy_subscribe_bboard,    /* subscribe to bboard */
  63.   dummy_unsubscribe_bboard,    /* unsubscribe from bboard */
  64.   dummy_create,            /* create mailbox */
  65.   dummy_delete,            /* delete mailbox */
  66.   dummy_rename,            /* rename mailbox */
  67.   dummy_open,            /* open mailbox */
  68.   dummy_close,            /* close mailbox */
  69.   dummy_fetchfast,        /* fetch message "fast" attributes */
  70.   dummy_fetchflags,        /* fetch message flags */
  71.   dummy_fetchstructure,        /* fetch message structure */
  72.   dummy_fetchheader,        /* fetch message header only */
  73.   dummy_fetchtext,        /* fetch message body only */
  74.   dummy_fetchbody,        /* fetch message body section */
  75.   dummy_setflag,        /* set message flag */
  76.   dummy_clearflag,        /* clear message flag */
  77.   dummy_search,            /* search for message based on criteria */
  78.   dummy_ping,            /* ping mailbox to see if still alive */
  79.   dummy_check,            /* check for new messages */
  80.   dummy_expunge,        /* expunge deleted messages */
  81.   dummy_copy,            /* copy messages to another mailbox */
  82.   dummy_move,            /* move messages to another mailbox */
  83.   dummy_append,            /* append string message to mailbox */
  84.   dummy_gc            /* garbage collect stream */
  85. };
  86.  
  87. /* Dummy validate mailbox
  88.  * Accepts: mailbox name
  89.  * Returns: our driver if name is valid, NIL otherwise
  90.  */
  91.  
  92. DRIVER *dummy_valid (char *name)
  93. {
  94.   return (name && *name) ? &dummydriver : NIL;
  95. }
  96.  
  97.  
  98. /* Dummy manipulate driver parameters
  99.  * Accepts: function code
  100.  *        function-dependent value
  101.  * Returns: function-dependent return value
  102.  */
  103.  
  104. void *dummy_parameters (long function,void *value)
  105. {
  106.   return NIL;
  107. }
  108.  
  109. /* Dummy find list of subscribed mailboxes
  110.  * Accepts: mail stream
  111.  *        pattern to search
  112.  */
  113.  
  114. void dummy_find (MAILSTREAM *stream,char *pat)
  115. {
  116.   /* Exit quietly */
  117. }
  118.  
  119.  
  120. /* Dummy find list of subscribed bboards
  121.  * Accepts: mail stream
  122.  *        pattern to search
  123.  */
  124.  
  125. void dummy_find_bboards (MAILSTREAM *stream,char *pat)
  126. {
  127.   /* Exit quietly */
  128. }
  129.  
  130.  
  131. /* Dummy find list of all mailboxes
  132.  * Accepts: mail stream
  133.  *        pattern to search
  134.  */
  135.  
  136. void dummy_find_all (MAILSTREAM *stream,char *pat)
  137. {
  138.                 /* always an INBOX */
  139.   if (pmatch ("INBOX",pat)) mm_mailbox ("INBOX");
  140. }
  141.  
  142.  
  143. /* Dummy find list of all bboards
  144.  * Accepts: mail stream
  145.  *        pattern to search
  146.  */
  147.  
  148. void dummy_find_all_bboards (MAILSTREAM *stream,char *pat)
  149. {
  150.   /* Exit quietly */
  151. }
  152.  
  153. /* Dummy subscribe to mailbox
  154.  * Accepts: mail stream
  155.  *        mailbox to add to subscription list
  156.  * Returns: T on success, NIL on failure
  157.  */
  158.  
  159. long dummy_subscribe (MAILSTREAM *stream,char *mailbox)
  160. {
  161.   return NIL;            /* always fails */
  162. }
  163.  
  164.  
  165. /* Dummy unsubscribe to mailbox
  166.  * Accepts: mail stream
  167.  *        mailbox to delete from subscription list
  168.  * Returns: T on success, NIL on failure
  169.  */
  170.  
  171. long dummy_unsubscribe (MAILSTREAM *stream,char *mailbox)
  172. {
  173.   return NIL;            /* always fails */
  174. }
  175.  
  176.  
  177. /* Dummy subscribe to bboard
  178.  * Accepts: mail stream
  179.  *        bboard to add to subscription list
  180.  * Returns: T on success, NIL on failure
  181.  */
  182.  
  183. long dummy_subscribe_bboard (MAILSTREAM *stream,char *mailbox)
  184. {
  185.   return NIL;            /* always fails */
  186. }
  187.  
  188.  
  189. /* Dummy unsubscribe to bboard
  190.  * Accepts: mail stream
  191.  *        bboard to delete from subscription list
  192.  * Returns: T on success, NIL on failure
  193.  */
  194.  
  195. long dummy_unsubscribe_bboard (MAILSTREAM *stream,char *mailbox)
  196. {
  197.   return NIL;            /* always fails */
  198. }
  199.  
  200. /* Dummy create mailbox
  201.  * Accepts: mail stream
  202.  *        mailbox name to create
  203.  *        driver type to use
  204.  * Returns: T on success, NIL on failure
  205.  */
  206.  
  207. long dummy_create (MAILSTREAM *stream,char *mailbox)
  208. {
  209.   return NIL;            /* always fails */
  210. }
  211.  
  212.  
  213. /* Dummy delete mailbox
  214.  * Accepts: mail stream
  215.  *        mailbox name to delete
  216.  * Returns: T on success, NIL on failure
  217.  */
  218.  
  219. long dummy_delete (MAILSTREAM *stream,char *mailbox)
  220. {
  221.   return NIL;            /* always fails */
  222. }
  223.  
  224.  
  225. /* Mail rename mailbox
  226.  * Accepts: mail stream
  227.  *        old mailbox name
  228.  *        new mailbox name
  229.  * Returns: T on success, NIL on failure
  230.  */
  231.  
  232. long dummy_rename (MAILSTREAM *stream,char *old,char *new)
  233. {
  234.   return NIL;            /* always fails */
  235. }
  236.  
  237. /* Dummy open
  238.  * Accepts: stream to open
  239.  * Returns: stream on success, NIL on failure
  240.  */
  241.  
  242. MAILSTREAM *dummy_open (MAILSTREAM *stream)
  243. {
  244.   int fd;
  245.   char tmp[MAILTMPLEN];
  246.                 /* OP_PROTOTYPE call or silence */
  247.   if (!stream || stream->silent) return NIL;
  248.   if (*stream->mailbox == '*')    /* is it a bboard? */
  249.     sprintf (tmp,"No such bboard: %s",stream->mailbox+1);
  250.                 /* remote specification? */
  251.   else if (*stream->mailbox == '{')
  252.     sprintf (tmp,"Invalid remote specification: %s",stream->mailbox);
  253.   else if ((fd = open (dummy_file (tmp,stream->mailbox),O_RDONLY,NIL)) < 0)
  254.     sprintf (tmp,"%s: %s",strerror (errno),stream->mailbox);
  255.   else {            /* must be bogus format file */
  256.     sprintf (tmp,"%s is not a mailbox",stream->mailbox);
  257.     close (fd);            /* toss out the fd */
  258.   }
  259.   mm_log (tmp,ERROR);
  260.   return NIL;            /* always fails */
  261. }
  262.  
  263.  
  264. /* Dummy close
  265.  * Accepts: MAIL stream
  266.  */
  267.  
  268. void dummy_close (MAILSTREAM *stream)
  269. {
  270.   /* Exit quietly */
  271. }
  272.  
  273. /* Dummy fetch fast information
  274.  * Accepts: MAIL stream
  275.  *        sequence
  276.  */
  277.  
  278. void dummy_fetchfast (MAILSTREAM *stream,char *sequence)
  279. {
  280.   fatal ("Impossible dummy_fetchfast");
  281. }
  282.  
  283.  
  284. /* Dummy fetch flags
  285.  * Accepts: MAIL stream
  286.  *        sequence
  287.  */
  288.  
  289. void dummy_fetchflags (MAILSTREAM *stream,char *sequence)
  290. {
  291.   fatal ("Impossible dummy_fetchflags");
  292. }
  293.  
  294.  
  295. /* Dummy fetch envelope
  296.  * Accepts: MAIL stream
  297.  *        message # to fetch
  298.  *        pointer to return body
  299.  * Returns: envelope of this message, body returned in body value
  300.  */
  301.  
  302. ENVELOPE *dummy_fetchstructure (MAILSTREAM *stream,long msgno,BODY **body)
  303. {
  304.   fatal ("Impossible dummy_fetchstructure");
  305.   return NIL;
  306. }
  307.  
  308.  
  309. /* Dummy fetch message header
  310.  * Accepts: MAIL stream
  311.  *        message # to fetch
  312.  * Returns: message header in RFC822 format
  313.  */
  314.  
  315. char *dummy_fetchheader (MAILSTREAM *stream,long msgno)
  316. {
  317.   fatal ("Impossible dummy_fetchheader");
  318.   return NIL;
  319. }
  320.  
  321. /* Dummy fetch message text (body only)
  322.  * Accepts: MAIL stream
  323.  *        message # to fetch
  324.  * Returns: message text in RFC822 format
  325.  */
  326.  
  327. char *dummy_fetchtext (MAILSTREAM *stream,long msgno)
  328. {
  329.   fatal ("Impossible dummy_fetchtext");
  330.   return NIL;
  331. }
  332.  
  333.  
  334. /* Berkeley fetch message body as a structure
  335.  * Accepts: Mail stream
  336.  *        message # to fetch
  337.  *        section specifier
  338.  * Returns: pointer to section of message body
  339.  */
  340.  
  341. char *dummy_fetchbody (MAILSTREAM *stream,long m,char *sec,unsigned long *len)
  342. {
  343.   fatal ("Impossible dummy_fetchbody");
  344.   return NIL;
  345. }
  346.  
  347.  
  348. /* Dummy set flag
  349.  * Accepts: MAIL stream
  350.  *        sequence
  351.  *        flag(s)
  352.  */
  353.  
  354. void dummy_setflag (MAILSTREAM *stream,char *sequence,char *flag)
  355. {
  356.   fatal ("Impossible dummy_setflag");
  357. }
  358.  
  359.  
  360. /* Dummy clear flag
  361.  * Accepts: MAIL stream
  362.  *        sequence
  363.  *        flag(s)
  364.  */
  365.  
  366. void dummy_clearflag (MAILSTREAM *stream,char *sequence,char *flag)
  367. {
  368.   fatal ("Impossible dummy_clearflag");
  369. }
  370.  
  371.  
  372. /* Dummy search for messages
  373.  * Accepts: MAIL stream
  374.  *        search criteria
  375.  */
  376.  
  377. void dummy_search (MAILSTREAM *stream,char *criteria)
  378. {
  379.   fatal ("Impossible dummy_search");
  380. }
  381.  
  382. /* Dummy ping mailbox
  383.  * Accepts: MAIL stream
  384.  * Returns: T if stream alive, else NIL
  385.  * No-op for readonly files, since read/writer can expunge it from under us!
  386.  */
  387.  
  388. long dummy_ping (MAILSTREAM *stream)
  389. {
  390.   fatal ("Impossible dummy_ping");
  391.   return NIL;
  392. }
  393.  
  394.  
  395. /* Dummy check mailbox
  396.  * Accepts: MAIL stream
  397.  * No-op for readonly files, since read/writer can expunge it from under us!
  398.  */
  399.  
  400. void dummy_check (MAILSTREAM *stream)
  401. {
  402.   fatal ("Impossible dummy_check");
  403. }
  404.  
  405.  
  406. /* Dummy expunge mailbox
  407.  * Accepts: MAIL stream
  408.  */
  409.  
  410. void dummy_expunge (MAILSTREAM *stream)
  411. {
  412.   fatal ("Impossible dummy_expunge");
  413. }
  414.  
  415. /* Dummy copy message(s)
  416.  * Accepts: MAIL stream
  417.  *        sequence
  418.  *        destination mailbox
  419.  * Returns: T if copy successful, else NIL
  420.  */
  421.  
  422. long dummy_copy (MAILSTREAM *stream,char *sequence,char *mailbox)
  423. {
  424.   fatal ("Impossible dummy_copy");
  425.   return NIL;
  426. }
  427.  
  428.  
  429. /* Dummy move message(s)
  430.  * Accepts: MAIL stream
  431.  *        sequence
  432.  *        destination mailbox
  433.  * Returns: T if move successful, else NIL
  434.  */
  435.  
  436. long dummy_move (MAILSTREAM *stream,char *sequence,char *mailbox)
  437. {
  438.   fatal ("Impossible dummy_move");
  439.   return NIL;
  440. }
  441.  
  442.  
  443. /* Dummy append message string
  444.  * Accepts: mail stream
  445.  *        destination mailbox
  446.  *        stringstruct of message to append
  447.  * Returns: T on success, NIL on failure
  448.  */
  449.  
  450. long dummy_append (MAILSTREAM *stream,char *mailbox,STRING *message)
  451. {
  452.   int fd = -1,e;
  453.   char tmp[MAILTMPLEN];
  454.                 /* see if such a file */
  455.   if ((*mailbox != '*') && (*mailbox != '{') &&
  456.       (fd = open (dummy_file (tmp,mailbox),O_RDONLY,NIL)) < 0) {
  457.     if ((e = errno) == ENOENT)    /* failed, was it no such file? */
  458.       mm_notify (stream,"[TRYCREATE] Must create mailbox before append",
  459.          (long) NIL);
  460.     sprintf (tmp,"%s: %s",strerror (e),mailbox);
  461.   }
  462.   else {            /* must be bogus format file */
  463.     sprintf (tmp,"%s is not a valid mailbox",mailbox);
  464.     close (fd);            /* toss out the fd */
  465.   }
  466.   mm_log (tmp,ERROR);        /* pass up error */
  467.   return NIL;            /* always fails */
  468. }
  469.  
  470.  
  471. /* Dummy garbage collect stream
  472.  * Accepts: mail stream
  473.  *        garbage collection flags
  474.  */
  475.  
  476. void dummy_gc (MAILSTREAM *stream,long gcflags)
  477. {
  478.   fatal ("Impossible dummy_gc");
  479. }
  480.  
  481. /* Dummy mail generate file string
  482.  * Accepts: temporary buffer to write into
  483.  *        mailbox name string
  484.  * Returns: local file string
  485.  */
  486.  
  487. char *dummy_file (char *dst,char *name)
  488. {
  489.   char *s;
  490.   ucase (strcpy (dst,name));    /* copy name */
  491.                 /* absolute path name? */
  492.   if (!((*name == '\\') || name[1] == ':'))
  493.     sprintf (dst,"%s\\%s",myhomedir (),name);
  494.   return ucase (dst);
  495. }
  496.